home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Telnet 2.6.1d1 4⁄26⁄94 Folder / source / tek / tekrgmac.c < prev    next >
Text File  |  1994-04-18  |  13KB  |  580 lines

  1. /*
  2. rgmac.c by Gaige B. Paulsen
  3.   spawned from rgp.c by Aaron Contorer for NCSA
  4. Copyright 1987, board of trustees, University of Illinois
  5.  
  6. Routines for Macintosh Window output.  
  7. */
  8.  
  9. #ifdef MPW
  10. #pragma segment TEKMAIN
  11. #endif
  12.  
  13. #include <stdio.h>
  14. #include <String.h>
  15. #include <Packages.h>
  16.  
  17. #include "tekrgmac.proto.h"
  18. #include "TelnetHeader.h"
  19. #include "maclook.proto.h"
  20. #include "vgtek.proto.h"
  21. #include "mydnr.proto.h"
  22. #include "rsmac.proto.h"
  23. #include "netevent.proto.h"
  24. #include "rg0.proto.h"
  25. #include "rgmp.proto.h"
  26. #include "InternalEvents.h"
  27. #include "tekdefs.h"        /* NCSA: sb - all the TEK defines are now here */
  28.  
  29. #define TEK_DEBUG1
  30. #ifdef    TEK_DEBUG1
  31. #include "debug.h"
  32. #define    TEK_DEBUG_PRINT(x)    putln(x)
  33. char    TEK_DEBUG_STRING    [512];
  34. #else
  35. #define    TEK_DEBUG(x)
  36. #endif
  37.  
  38. /*--------------------------------------------------------------------------*/
  39. /* Some variable definitions are needed before we give the code                */
  40. /*                                                                             */
  41. /*--------------------------------------------------------------------------*/
  42.  
  43. long    RGMlastclick;
  44. short    RGMcolor[]=
  45.     { 30,            /* black */
  46.       33,            /* white */
  47.       205,            /* red */
  48.       341,            /* green */
  49.       409,            /* blue */
  50.       273,            /* cyan */
  51.       137,            /* magenta */
  52.       69            /* yellow */
  53.       };
  54.  
  55. struct    RGMwindows *RGMwind[ MAXWIND ];
  56.  
  57. char    *RGMdevname(void)
  58. {
  59.     return("Macintosh Windows");
  60. }
  61.  
  62. short    RGMnewwin(void)
  63. {
  64.     short    i = 0;
  65.  
  66.     while ((i < MAXWIND) && (RGMwind[i]->inuse)) i++;
  67.  
  68.     if (i >= MAXWIND) return(-1);
  69.  
  70.     RGMwind[i]->wind = GetNewWindow(256, NULL, kInFront);
  71.     if (RGMwind[i]->wind == 0L) return(-1);
  72.  
  73.     ((WindowPeek)RGMwind[i]->wind)->windowKind = WIN_TEK;
  74.     
  75.     RGMwind[i]->vg = -1;                /* BYU */
  76.     RGMwind[i]->vs = -1;                /* BYU */
  77.     RGMwind[i]->xorigin = 0;
  78.     RGMwind[i]->yorigin = 0;
  79.     RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  80.     RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  81.     RGMwind[i]->width   = 400;        /* BYU LSC - was 256 (size of old window resource */
  82.     RGMwind[i]->height  = 300;        /* BYU LSC - was 342 (size of old window resource */
  83.     RGMwind[i]->inuse   = TRUE;
  84.     RGMwind[i]->ingin   = 0;        /* BYU LSC */
  85.  
  86.     ValidRect(&RGMwind[i]->wind->portRect);  
  87.  
  88.     return(i);
  89. }
  90.  
  91. void    RGMinit(void)
  92. {
  93.     short    i;
  94.     for (i = 0; i < MAXWIND; i++)
  95.         RGMwind[i]->inuse = 0;
  96. }
  97.  
  98. short    RGMgin(short w)
  99. {
  100.     if (RGsetwind(w)) return(-1);
  101.  
  102.     setgraphcurs();
  103.     RGMwind[w]->ingin=1;
  104. }
  105.  
  106. short    RGMpencolor(short w, short color)
  107. {
  108.     if (RGsetwind(w) ) return(-1);
  109.     ForeColor((long) RGMcolor[color] );
  110. #ifdef    TEK_DEBUG_1
  111.     sprintf(TEK_DEBUG_STRING, "TEK: Setting pen color to %d", color);
  112.     putln(TEK_DEBUG_STRING);
  113. #endif
  114.  
  115. }
  116.  
  117. short    RGMclrscr(short w)
  118. {    
  119.     if (RGsetwind(w) ) return(-1);
  120.     PaintRect(&RGMwind[w]->wind->portRect);
  121.     TEK_DEBUG_PRINT("TEK: Clearing screen");                    
  122. }    
  123.  
  124. short    RGMclose(short w)
  125. {
  126.     if (RGsetwind(w) ) return(-1);
  127.  
  128.     DisposeWindow(RGMwind[w]->wind);
  129.     RGMwind[w]->inuse  = FALSE;
  130. }
  131.  
  132. short    RGMpoint(short w, short x, short y)
  133. {
  134.     if (RGsetwind(w) ) return(-1);
  135.  
  136.     MoveTo(x,y);
  137.     LineTo(x,y);
  138.  
  139. short    RGMdrawline(short w, short x0, short y0, short x1, short y1)
  140. {
  141.     long    xl0, yl0, xl1, yl1;
  142.     
  143.     if (RGsetwind(w) )
  144.         return(-1);
  145.  
  146.     xl0 = ((long)x0 * RGMwind[w]->width) / INXMAX;
  147.     yl0 = (long)RGMwind[w]->height - (((long)y0 * RGMwind[w]->height) / INYMAX);
  148.     xl1 = ((long)x1 * RGMwind[w]->width) / INXMAX;
  149.     yl1 = (long)RGMwind[w]->height - (((long)y1 * RGMwind[w]->height) / INYMAX);
  150.  
  151.     MoveTo((short)xl0, (short)yl0);
  152.     LineTo((short)xl1, (short)yl1);
  153. }
  154.  
  155. void    RGMinfo(short w, short v, short a, short b, short c, short d)
  156. {
  157. #pragma unused(a, b, c, d)
  158.     RGMwind[w]->vg=v;
  159. }
  160.  
  161. void    RGMpagedone(short w)
  162. {
  163. #pragma unused(w)
  164. }
  165.  
  166. void    RGMdataline(short w, short data, short count)
  167. {
  168. #pragma unused(w, data, count)
  169. }
  170.  
  171.  
  172. void    RGMcharmode(short w, short rotation, short size)
  173. {
  174. #pragma unused(w, rotation, size)
  175. }
  176.  
  177. void    RGMgmode(void)
  178. {}
  179.  
  180. void    RGMtmode(void)
  181. {}
  182.  
  183. void    RGMshowcur(void)
  184. {
  185. }
  186.  
  187. void    RGMlockcur(void)
  188. {
  189. }
  190.  
  191. void    RGMhidecur(void)
  192. {
  193. }
  194.  
  195. void    RGMbell(short w)
  196. {
  197. #pragma unused(w)
  198. }
  199.  
  200. void    RGMuncover(short w)
  201. {
  202. #pragma unused(w)
  203. }
  204.  
  205. short    RGMoutfunc(short (*f )())
  206. {
  207. #pragma unused(f)
  208.     return(0);    // Unused
  209. }
  210.  
  211. Boolean RGMalloc(void)        /* BYU - allocate this structure to save global space */
  212. {
  213.     short i;
  214.     for(i=0; i<MAXWIND; i++) {        /* BYU */
  215.         RGMwind[i] = (struct RGMwindows *) NewPtrClear(sizeof(struct RGMwindows));    /* BYU */
  216.         if (RGMwind[i]) {                        /* BYU */
  217.             RGMwind[i]->wind = (GrafPtr) 0;        /* BYU */
  218.             RGMwind[i]->id = 'RGMW';
  219.             RGMwind[i]->vg = -1;                /* BYU - necessary */
  220.             RGMwind[i]->vs = -1;                /* BYU */
  221.             RGMwind[i]->inuse = 0;                /* BYU - necessary */
  222.         } else                                     /* BYU */
  223.             return (TRUE);                /* BYU - insufficient memory */
  224.     }
  225.     return(FALSE);
  226. }
  227.  
  228. short    RGsetwind(short dnum)
  229. {
  230.     if (dnum<0 || dnum>=MAXWIND) return(-1);
  231.  
  232.     if (!RGMwind[dnum]->inuse) return(-1);
  233.  
  234.     SetPort( RGMwind[dnum]->wind);
  235.     return(0);
  236. }
  237.  
  238. short    RGfindbyVG(short vg)
  239. {
  240.     short    i = 0;
  241.  
  242.     while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->vg != vg)))
  243.         i++;
  244.     if (i >= MAXWIND) return(-1);
  245.     return(i);
  246. }
  247.  
  248. short    RGattach(short vg, short virt, char *name, short TEKtype)
  249. {
  250.     short            dnum;
  251.     unsigned long    time;
  252.     char            myname[256],ts[256];
  253.  
  254.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);
  255.  
  256.     RGMwind[dnum]->vs = virt;
  257.     RGMwind[dnum]->name = (unsigned char *) NewPtrClear((long) 256);        /* BYU LSC */
  258.  
  259.     if (RGMwind[dnum]->name == 0L) return(-2);
  260.  
  261.     myname[0] = '•';
  262.     if (TEKtype)
  263.         strcpy(&myname[1], "[4105] ");
  264.     else
  265.         strcpy(&myname[1], "[4014] ");
  266.         
  267.     strncpy(&myname[strlen(myname)],name,120);
  268.  
  269.     GetDateTime(&time);
  270.     IUTimeString(time,FALSE,(StringPtr) ts);        /* BYU LSC - Put time in the temp string */
  271.     p2cstr((StringPtr)ts);                                            /* BYU LSC */
  272.  
  273.     strncat(myname,"  ",2);                /* BYU - was 4 - Space, please */
  274.     strncat(myname,ts,64);                /* BYU - Place the time string at the end */
  275.     strcpy((char *) RGMwind[dnum]->name,myname);    /* BYU LSC */
  276.  
  277.     if (RGMwind[dnum]->wind != (GrafPtr) 0) {    /* BYU LSC */
  278.         c2pstr(myname);                            /* BYU LSC */
  279.         SetWTitle(RGMwind[dnum]->wind,(StringPtr)myname);    /* BYU LSC */
  280.     }
  281.  
  282.     return(0);
  283. }
  284.  
  285.  
  286. short    RGdetach( short vg)
  287. {
  288.         short    dnum;            /* BYU */
  289.         char    myname[256];            /* BYU LSC */
  290.  
  291.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);        /* BYU */
  292.     if (dnum >= MAXWIND)  return(-1);                    /* BYU */
  293.  
  294.     if (RGMwind[dnum]->vs != -1) {                                     /* BYU */
  295.         if (RGMwind[dnum]->wind != (GrafPtr) 0) {                    /* BYU */
  296. #if 1
  297.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  298.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  299.             strncpy(myname, (char *) RGMwind[dnum]->name,256);    /* BYU LSC */
  300.             c2pstr(myname);                                        /* BYU LSC */
  301.             SetWTitle(RGMwind[dnum]->wind,(StringPtr)myname);                /* BYU LSC */
  302. #else
  303.             strncpy((char *) RGMwind[dnum]->name,                /* BYU LSC */
  304.                     (char *) &RGMwind[dnum]->name[1],255);        /* BYU LSC */
  305.             SetWTitle(RGMwind[dnum]->wind,RGMwind[dnum]->name);    /* BYU LSC */
  306. #endif
  307.         }                            /* BYU */
  308.     }                                /* BYU */
  309.     return(0);                        /* BYU */
  310. }
  311.  
  312. short    RGfindbywind( GrafPtr wind)
  313. {
  314.     short    i = 0;
  315.  
  316.     while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->wind != wind)))
  317.         i++;
  318.     if (i >= MAXWIND) return(-1);
  319.     return(i);
  320. }
  321.  
  322. short    RGupdate( GrafPtr wind)
  323. {
  324.     short    i = 0,
  325.             done;
  326.  
  327.     if ((i = RGfindbywind(wind)) < 0)
  328.         return(-1);
  329.  
  330.     SetPort(wind);
  331.     BeginUpdate(wind);
  332.  
  333.     VGstopred(RGMwind[i]->vg);
  334.     VGpage(RGMwind[i]->vg);
  335.     done = VGpred(RGMwind[i]->vg,RGMwind[i]->vg);
  336.  
  337.     EndUpdate(wind);
  338.     if (!done)
  339.         netputevent(USERCLASS,RG_REDRAW,RGMwind[i]->vg,0);
  340.     return(done);
  341. }
  342.  
  343. short    RGsupdate( short i)
  344. {
  345.     short    rg;
  346.  
  347.     rg = RGfindbyVG(i);
  348.  
  349.     if (rg < 0) return(0);
  350.     SetPort(RGMwind[rg]->wind);
  351.     if (!VGpred(RGMwind[rg]->vg,RGMwind[rg]->vg))
  352.     {
  353.         netputevent(USERCLASS,RG_REDRAW,i,0);
  354.     }
  355.     else
  356.         return(1);
  357.     return(0);
  358. }
  359.  
  360. short    RGgetVG(GrafPtr wind)
  361. {
  362.     short    i;
  363.  
  364.     i = RGfindbywind(wind);
  365.  
  366.     return(RGMwind[i]->vg);
  367. }
  368.  
  369. short    RGgetdnum(GrafPtr wind)
  370. {
  371.     return(RGfindbywind(wind));
  372. }
  373.  
  374. short    RGgetVS(short dnum)
  375. {
  376.     return(RGMwind[dnum]->vs);
  377. }
  378.  
  379. short    inSplash(Point *p1, Point *p2)
  380. {
  381.     if ((p1->h - p2->h > 3) || (p2->h - p1->h > 3))
  382.         return(0);
  383.     if ((p1->v - p2->v > 3) || (p2->v - p1->v > 3))
  384.         return(0);
  385.  
  386.     return(1);
  387. }
  388.  
  389. void VidSync( void)
  390. {
  391.     long    a;
  392.     a = TickCount();            /* BYU LSC */
  393.     while (a == TickCount());    /* BYU LSC */
  394. }
  395.  
  396. void RGmousedown
  397.   (
  398.     GrafPtr wind,
  399.     Point *wherein
  400.   )
  401. {
  402.     unsigned long    lx,ly;        /* NCSA: SB */
  403.     char            thispaceforent[6];
  404.     short            i;
  405.     Point            where;
  406.     char            dum[32];
  407.  
  408.     where = *wherein;
  409.     if ((i = RGfindbywind(wind)) < 0)
  410.         return;
  411.  
  412.     if (!RGMwind[i]->ingin)
  413.     {
  414.     Point    anchor,current,last;
  415. #if 0                            /* BYU LSC - was "#ifndef MPW" */
  416.     long    TickCount();
  417. #endif MPW
  418.     long    tc;
  419.     short    x0,y0,x1,y1;
  420.     Rect    rect;
  421.     
  422.         SetPort(wind);
  423.     
  424.         last  = where;
  425.         current = where;
  426.         anchor = where;
  427.     
  428.         PenPat(PATTERN(qd.gray));    
  429.         PenMode(patXor);
  430.     
  431.         SetRect(&rect,0,0,0,0);
  432.     
  433.         while (StillDown())
  434.         {
  435.             GetMouse(¤t);
  436.             if (inSplash(¤t,&anchor)) continue;
  437.             tc = TickCount();
  438.             while(TickCount() == tc);
  439.             VidSync();
  440.             FrameRect(&rect);
  441.     
  442.             if (anchor.v < current.v)
  443.             {
  444.                 rect.top = anchor.v;
  445.                 rect.bottom = current.v;
  446.             }
  447.             else
  448.             {
  449.                 rect.top = current.v;
  450.                 rect.bottom = anchor.v;
  451.             }
  452.     
  453.             if (anchor.h < current.h)
  454.             {
  455.                 rect.left = anchor.h;
  456.                 rect.right = current.h;
  457.             }
  458.             else
  459.             {
  460.                 rect.right = anchor.h;
  461.                 rect.left = current.h;
  462.             }
  463.     
  464.             FrameRect(&rect);
  465.             last = current;
  466.         }
  467.     
  468.         FrameRect(&rect);
  469.  
  470.         PenPat(PATTERN(qd.black));    
  471.         PenMode(patCopy);
  472.  
  473.         if (!inSplash(&anchor,¤t))
  474.         {
  475.             x0 = (short) ((long) rect.left * RGMwind[i]->xscale / RGMwind[i]->width );
  476.             y0 = (short) (RGMwind[i]->yscale -
  477.                     (long) rect.top * RGMwind[i]->yscale / RGMwind[i]->height);
  478.             x1 = (short) ((long) rect.right * RGMwind[i]->xscale / RGMwind[i]->width);
  479.             y1 = (short) (RGMwind[i]->yscale -
  480.                     (long) rect.bottom * RGMwind[i]->yscale / RGMwind[i]->height);
  481.             x1 = (x1 < x0+2) ? x0 + 4 : x1;
  482.             y0 = (y0 < y1+2) ? y1 + 4 : y0;
  483.  
  484.             VGzoom( i,
  485.                     x0 + RGMwind[i]->xorigin,
  486.                     y1 + RGMwind[i]->yorigin,
  487.                     x1 + RGMwind[i]->xorigin,
  488.                     y0 + RGMwind[i]->yorigin);
  489.  
  490.             VGpage(RGMwind[i]->vg);
  491.  
  492.             RGMwind[i]->xscale  = x1 - x0;
  493.             RGMwind[i]->yscale  = y0 - y1;
  494.             RGMwind[i]->xorigin = x0 + RGMwind[i]->xorigin;
  495.             RGMwind[i]->yorigin = y1 + RGMwind[i]->yorigin;
  496.  
  497.             while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  498.                 Stask();
  499.             RGMlastclick = 0L;
  500.         }
  501.         else
  502.         {
  503.             if (RGMlastclick && ((RGMlastclick + GetDblTime()) > TickCount()))
  504.             {
  505.                 RGMwind[i]->xscale  = WINXMAX;    /* BYU LSC - need the "W" here */
  506.                 RGMwind[i]->yscale  = WINYMAX;    /* BYU LSC - need the "W" here */
  507.                 RGMwind[i]->xorigin = 0;
  508.                 RGMwind[i]->yorigin = 0;
  509.  
  510.                 VGzoom(i,0,0,WINXMAX-1,WINYMAX-1);    /* BYU LSC - need the "W" here */
  511.                 VGpage( RGMwind[i]->vg);
  512.                 while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  513.                     Stask();
  514.                 RGMlastclick = 0L;
  515.             }
  516.             else RGMlastclick = TickCount();
  517.         }
  518.         return;
  519.     
  520.     }
  521.     
  522.     /* NCSA: SB */
  523.     /* NCSA: SB - These computations are being truncated and turned into signed ints. */
  524.     /* NCSA: SB - Just make sure everything is cast correctly, and were fine */
  525.     
  526.     lx = ((unsigned long)RGMwind[i]->xscale * (unsigned long)where.h)     /* NCSA: SB */
  527.             / (unsigned long)RGMwind[i]->width;                             /* NCSA: SB */
  528.     ly = (unsigned long)RGMwind[i]->yscale -                             /* NCSA: SB */
  529.         ((unsigned long)RGMwind[i]->yscale * (unsigned long)where.v) / (unsigned long)RGMwind[i]->height; /* NCSA: SB */
  530.  
  531.     VGgindata(RGMwind[i]->vg,(unsigned short) lx,(unsigned short)ly,' ',thispaceforent);    /* NCSA: SB */
  532.  
  533. #if 0                                                    /* BYU LSC - not needed */
  534. sprintf(dum,"GIN i: %d, vs: %d\015",i,RGMwind[i]->vs);    /* BYU 2.4.18 - changed \n to \015 */
  535. putln(dum);
  536. #endif                                                    /* BYU LSC - not needed */
  537.  
  538.     RSsendstring(RGMwind[i]->vs,thispaceforent,5);
  539.     sprintf(dum," \r\n");
  540.     RSsendstring(RGMwind[i]->vs,dum,3);
  541.     
  542.  
  543.     /*    RGMwind[i]->ingin = 0; */
  544.     unsetgraphcurs();
  545.     RGMlastclick = TickCount();
  546. }
  547.  
  548.  
  549. /*--------------------------------------------------------------------------*/
  550. /* NCSA: SB - RGMgrowme                                                        */
  551. /* This allows the TEK window to be grown like any other real window.        */
  552. /* The grow box is not shown on the screen, but it acts accordingly     - SMB    */
  553. /*--------------------------------------------------------------------------*/
  554. void    RGMgrowme(short myRGMnum,GrafPtr window, long *where, short modifiers)
  555. {
  556.     #pragma unused (modifiers)
  557.     long size;
  558.     Rect SizRect;
  559.  
  560.     SetRect(&SizRect, 50, 50, 1500, 1500);            /* NCSA: SB - max size - arbitrary */
  561.  
  562.     if (where)
  563.     {        
  564.         size = GrowWindow(window, *(Point *) where, &SizRect);    
  565.         if (size != 0L)
  566.             {
  567.             SizeWindow(window, size & 0xffff, (size >> 16) & 0xffff, FALSE);
  568.             RGMwind[myRGMnum]->width   = window->portRect.right - window->portRect.left;        
  569.             RGMwind[myRGMnum]->height  = window->portRect.bottom - window->portRect.top;         
  570.             VGpage(RGMwind[myRGMnum]->vg);
  571.             InvalRect(&window->portRect);
  572.             RGupdate(window);
  573.             }
  574.         else
  575.             return;                            /* user skipped growing */
  576.     }
  577. }
  578.  
  579.